<template>
  <div class="noteitem" v-if="songitem">
    <div class="head">
      <div class="left">
        <div class="back" @click="back">
          <img src="../assets/img/back.png" alt="" />
        </div>
        <router-link tag="div" :to="'/useritem?id='+ songitem.user.id" class="heads" >
        <img :src=" songitem.user.avatar" alt=""> 
           
         
        </router-link>
        <!-- <div class="vip" v-show="songitem.user.vip_flag>0">
          <img src="../assets/img/O_1.png" alt="" />
        </div> -->
        <div class="name">{{songitem.user.username}}</div>
      </div>
      <div class="right">
        <!-- <div class="gzhu">
        <img src="../assets/img/add.png" alt="">
        <span>关注</span>
       </div> -->
        <!-- <div class="havegzhu">
          <span>已关注</span>
        </div> -->
        <div class="share">
          <img src="../assets/img/share1.png" alt="" />
        </div>
      </div>
    </div>
    <div class="content">
      <div class="content_img">
        <span v-for="(item,index) in songitem.images" :key="index">
         <img :src="item" alt="" />
       </span>
         
      </div>
     <div class="title">
       <p>{{songitem.title}}</p>
     </div>
      <h4>{{songitem.content}}</h4>
      <h4 class="con" v-if="songitem.topics">{{songitem.topics[0].name}}</h4>
      <h6>{{songitem.ip_location}}</h6>
    </div>
    <div class="comments" v-if="songcomment">
      <div class="num">
        <h5 v-if="songcomment.length>0">一共{{songcomment.length}}条评论</h5>
      </div>
      <div class="comments_item" v-for="item in songcomment" :key="item.id">
        <div class="left">
          <div class="bgimg">
            <img :src="item.userDetail.avatar_big" alt="">
          </div>
          <!-- <div class="v">
            <img src="../assets/img/zq.png" alt="" />
          </div> -->
          <div class="left_content">
            <h6>{{item.userDetail.nickname}}</h6>
            <span class="one">{{item.contentText}}</span>
            <span class="two">{{item.createTimeUnix|dateFormat}}`{{item.ipLocation}}</span>
          </div>
        </div>
        <div class="right">
          <!-- <span>1</span> -->
          <img src="../assets/img/Vx.png" alt="" />
          <!-- <img src="../assets/img/likes.png" alt=""> -->
        </div>
      </div>
    </div>
    <p>暂时没有更多了</p>
    <div class="commentsbar">
      <div class="left">
        <span class="img">
          <img src="../assets/img/writes.png" alt="" />
        </span>
        <span class="ins">
          <input type="text" placeholder="说说你的看法吧~" />
        </span>
        <span class="tian"></span>
      </div>
      <div class="right">
        <div class="likeit">
          <img src="../assets/img/Vx.png" alt="" />
          <!-- <img src="../assets/img/likes.png" alt="" /> -->
          <span>{{songitem.count.count_liked}}</span>
        </div>
        <div class="pinglun">
          <img src="../assets/img/Comments.png" alt="" />
          <span>{{songitem.count.count_commented}}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import { getSongitem } from "../api/songitem";
import axios from "axios";
export default {
  data() {
    return {
      songitem: null,
      songcomment:null,
    };
  },
  methods: {
    // getSongitemFun(){
    //   getSongitem().then(data=>{
    //        this.songitem=data
    //        console.log(this.songitem);
    //   })
    // },
    getSongitem(id) {
      axios.get(`https://apis.netstart.cn/xpc/note/${id}`).then((data) => {
        console.log(data);
        if (data.data.message=='OK') {
          this.songitem=data.data.data
        }
        else{
          let temp =JSON.parse(window.localStorage.getItem('note'))
          console.log(temp);
          this.songitem=temp
        }
        
      });
    },
    getSongcomment(id){
      // https://apis.netstart.cn/xpc/note/5849/comment
       axios.get(`https://apis.netstart.cn/xpc/note/${id}/comment`).then((data) => {
        this.songcomment=data.data.data
        console.log(this.songcomment);
      });
      
    },
    back(){
      this.$router.go(-1)
    }
   
  },
  created() {
    
    // 获取手记详情页数据
    this.getSongitem(this.$route.query.id);
    // 获取手记详情页评论
    this.getSongcomment(this.$route.query.id)

  },
  filters: {
			dateFormat(val){
				let date = new Date(val);
				
				let M = date.getMonth().toString().padStart(2,"0");
				let d = date.getDate().toString().padStart(2,"0");
				
				return `${M}-${d}`
			}
		}
	}
</script>
 


<style lang="less" >
body {
  background-color: #fff;
}
.noteitem {
  .head {
    width: 100%;
    background-color: #fff;
    position: fixed;
    top: 0px;
    left: 0px;
    z-index: 55;
    right: 0px;
    display: flex;
    justify-content: space-between;
    padding: 10px 0px;
    border-bottom: 2px solid #f2f2f2;
    .left {
      display: flex;
      align-items: center;
      position: relative;
      .back {
        margin-right: 5px;
        margin-left: 10px;
        img {
          width: 25px;
        }
      }
      .heads {
        width: 30px;
        height: 30px;
        margin-right: 10px;
        img{
          border-radius: 50%;
          height: 30px;
          width: 30px;
        }
      }
      .vip {
        position: absolute;
        top: 18px;
        left: 60px;
        img {
          width: 12px;
        }
      }
      .name {
        font-size: 13px;
        font-weight: 600;
          text-overflow:ellipsis;
       overflow: hidden;
        display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 1; 
      }
    }
    .right {
      display: flex;
      align-items: center;
      .gzhu {
        padding: 4px 12px;
        margin-right: 20px;
        border: 1px solid salmon;
        border-radius: 15px;
        display: flex;
        align-items: center;

        img {
          width: 8px;
          height: 8px;
          margin-right: 5px;
        }
        span {
          font-size: 12px;
          color: salmon;
        }
      }
      .havegzhu {
        padding: 1px 12px;
        margin-right: 20px;
        border: 1px solid f2f2f2;
        border-radius: 15px;

        span {
          font-size: 14px;
          color: gray;
        }
      }
      .share {
        margin-right: 10px;
        img {
          width: 15px;
          height: 15px;
        }
      }
    }
  }
  .content {
    margin-top: 50px;
    background-color: #fff;
    padding: 15px 10px;
    padding-bottom: 0px;
    border-bottom: 1px solid #f2f2f2;
    .title{
      p{
        font-size: 14px;
       font-weight: 600;
       padding: 5px 0px;
       text-align: start;
       color: black;
      }
    }
    .content_img {
      display: flex;
      flex-wrap: wrap;
      
     span{
      width: 32%;
      display: inline-block;
      margin-right: 7px;
       img {
        width: 100%;
        height: 113px;
        margin-right: 17px;
        margin-bottom: 8px;
        border-radius: 5px;
      }
    
     }
      span:nth-child(3n + 3) {
        margin-right: 0px;
      }
    
     
    }

    h4 {
      font-size: 12px;
    }
    .con {
      color: blue;
    }
    h6 {
      padding: 10px 0px;
    }
  }
  .comments {
    padding: 0px 10px;
    background-color: #fff;
    .num {
      h5 {
        font-size: 14px;
        color: gray;
        padding: 10px 0px;
      }
    }
    .comments_item {
      display: flex;
      justify-content: space-between;
      padding: 15px 0px;
      border-bottom: 1px solid #f2f2f2;
      .left {
        display: flex;
        // align-items: center;
        position: relative;
        .bgimg {
          display: block;
          width: 30px;
          height: 30px;
          margin-right: 10px;
           img{
          border-radius: 50%;
          height: 30px;
          width: 30px;
        }
        }
        .v {
          position: absolute;
          left: 20px;
          top: 20px;
          img {
            width: 12px;
          }
        }
        .left_content {
          width: 80%;
          flex: 1;
          h6 {
            color: gray;
          }
          .one {
            font-size: 600;
            margin-right: 10px;
            font-size: 14px;
          }
          .two {
            color: gray;
            font-size: 10px;
          }
        }
      }
      .right {
        display: flex;
        padding-right: 10px;
        img {
          width: 15px;
          height: 15px;
        }
        span {
          display: block;
          color: salmon;
        }
      }
    }
  }
  p {
    text-align: center;
    background-color: #fff;
    padding: 20px 0px;
    color: gray;
    font-size: 14px;
    border-bottom: 1px solid #f2f2f2;
  }
  .commentsbar {
    box-sizing: border-box;
    width: 100%;
    padding: 15px 10px;
    position: fixed;
    bottom: 0px;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    .left {
      display: flex;

      .img {
        display: block;
        padding: 5px 0px;
        padding-left: 15px;
        border-top-left-radius: 30px;
        border-bottom-left-radius: 30px;
        background-color: #eeeeee;
        img {
          width: 20px;
        }
      }
      .ins {
        display: block;
        padding: 5px 0px;
        background-color: #eeeeee;
        input {
          display: block;
          border: none;
          outline: none;
          height: 20px;
          width: 150px;
          background-color: #eeeeee;
          font-size: 12px;
        }
      }
      .tian {
        display: block;
        padding: 5px 0px;
        width: 35px;
        height: 20px;
        border-top-right-radius: 30px;
        border-bottom-right-radius: 30px;
        background-color: #eeeeee;
      }
    }
    .right {
      display: flex;
      .likeit {
        width: 40px;
        display: flex;
        align-items: center;
        margin-right: 10px;

        span {
          display: block;
          font-size: 14px;
        }
        img {
          width: 20px;
          margin-right: 7px;
        }
      }
      .pinglun {
        display: flex;

        align-items: center;

        img {
          width: 20px;
          margin-right: 7px;
        }
        span {
          font-size: 14px;
        }
      }
    }
  }
}
</style>